package com.tac.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tac.common.result.Result;
import com.tac.pojo.Hotel;
import com.tac.pojo.vo.HotelVo;
import com.tac.service.HotelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.crypto.Data;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/hotel")
@Api(tags = "酒店")
public class HotelController {
    @Autowired
    private HotelService hotelService;

    /**
     * 查看所有酒店
     * @return
     */
    @GetMapping
    @ApiOperation("查看所有酒店")
    public Result<List<Hotel>> seleceAll(){
        return hotelService.seleceAll();
    }

    /**
     * 查看酒店详情
     * @param hid
     * @param uid
     * @return
     */
    @GetMapping("/{hid}")
    @ApiOperation("查看酒店详情")
    public Result<HotelVo> selectById(@PathVariable Long hid, Long uid){
        return hotelService.selectById(hid,uid);
    }
    /**
     * 收藏酒店
     * @param hid
     * @param uid
     * @return
     */
    @PutMapping
    @ApiOperation("收藏酒店")
    public Result collection(Long hid, Long uid){
        return hotelService.collection(hid,uid);
    }
    /**
     * 取消收藏
     * @param hid
     * @param uid
     * @return
     */
    @PutMapping("/{hid}/{uid}")
    @ApiOperation("取消收藏")
    public Result deleteByCollection(@PathVariable Long hid, @PathVariable Long uid){
        return hotelService.deleteByCollection(hid,uid);
    }
    /**
     * 查看所有收藏的酒店
     * @param uid
     * @return
     */
    @ApiOperation("查看所有收藏的酒店")
    @GetMapping("/selectBycollection")
    public Result<List<Hotel>> selectBycollection(Long uid){
        return hotelService.selectBycollection(uid);
    }



    /**
     * 按创建时间搜索酒店
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/{page}/{pagesize}")
    @ApiOperation("按创建时间搜索酒店")
    public Result<Page<Hotel>> selectByTime(@PathVariable Long page,@PathVariable Long pagesize, String startTime, String endTime){
        return hotelService.selectByTime(page, pagesize, startTime, endTime);
    }
}
